package com.rongc.client.freight.business.supply.view.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;

import com.rongc.client.core.utils.DateUtil;
import com.rongc.client.core.utils.StringUtils;
import com.rongc.client.freight.R;
import com.rongc.client.freight.base.view.adapter.RecyclerBaseAdapter;
import com.rongc.client.freight.business.supply.model.SupplyCarBean;

import java.util.List;

/**
 * Created by ccqx on 2017/6/28.
 */

public class RecyclerSupplyConveyanceAdapter extends RecyclerBaseAdapter<SupplyCarBean>{


    public RecyclerSupplyConveyanceAdapter(Context mContext, List<SupplyCarBean> mDatas) {
        super(mContext, mDatas);
    }

    @Override
    protected void onBind(final BaseRecyclerViewHolder holder, int position, SupplyCarBean data) {
        holder.getImageView(R.id.tv_phone).setVisibility(View.VISIBLE);
        holder.setText(R.id.tv_departure,data.getStartPlace());
        holder.setText(R.id.tv_destination,data.getEndPlace());
        holder.setText(R.id.tv_distance, String.format(mContext.getResources().getString(R.string.supply_list_distance),
                StringUtils.makeDistance(StringUtils.parseDouble(data.getDistance()))));
        holder.setText(R.id.tv_create_date, DateUtil.getStringByFormat(data.getLoadTime(),DateUtil.dateFormatMD));
        holder.setText(R.id.tv_date,data.getLoadTime());
        holder.setText(R.id.tv_model,data.getCarModels());

        holder.getView(R.id.tv_phone).setTag(data.getPhone());
        holder.getView(R.id.tv_phone).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String number = (String)v.getTag();

                Intent intent = new Intent(Intent.ACTION_DIAL);
                Uri data = Uri.parse("tel:" + number);
                intent.setData(data);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.recycler_supply_conveyance_item;
    }
}
